package com.hex2int;

public class MacUtilsDemo {

	public static void main(String[] args) {
		String mac = "E7:F2:7A:01:00:4B:12:00";
		String macNo = "E7F27A01004B1200";
		String macLower = "e7f27a01004b1200";

		System.out.println(macNo.toLowerCase());
		System.out.println(macNo.length());
		System.out.println("================================================");
		int startPosition = 0;
		System.out.println(macNo.substring(startPosition, startPosition+=2));
		System.out.println(macNo.substring(startPosition, startPosition+=2));
		System.out.println(macNo.substring(startPosition, startPosition+=2));
		System.out.println(macNo.substring(startPosition, startPosition+=2));
		System.out.println(macNo.substring(startPosition, startPosition+=2));
		System.out.println(macNo.substring(startPosition, startPosition+=2));
		System.out.println(macNo.substring(startPosition, startPosition+=2));
		System.out.println(macNo.substring(startPosition, startPosition+=2));
		System.out.println("================================================");

		System.out.println(getMacStringWithColon(macNo));

	}

	public static String getMacStringWithColon(String macStr) {
		if(getMacStringLengthIf16(macStr, 16)) {
			StringBuilder sb = new StringBuilder(128);
			int startPosition = 0;
			sb.append(macStr.substring(startPosition, startPosition+=2)).append(":");
			sb.append(macStr.substring(startPosition, startPosition+=2)).append(":");
			sb.append(macStr.substring(startPosition, startPosition+=2)).append(":");
			sb.append(macStr.substring(startPosition, startPosition+=2)).append(":");
			sb.append(macStr.substring(startPosition, startPosition+=2)).append(":");
			sb.append(macStr.substring(startPosition, startPosition+=2)).append(":");
			sb.append(macStr.substring(startPosition, startPosition+=2)).append(":");
			sb.append(macStr.substring(startPosition, startPosition+=2));
			return sb.toString();
		}
		return null;
	}

	/**
	 * Returns true if Mac's String is 8
	 * @param macStr
	 * @return
	 */
	private static boolean getMacStringLengthIf16(String macStr, int length){
		if(isEmpty(macStr) && macStr.length() != length) {
			return false;
		}
		return true;
	}


	/**
	 * Returns true if the string is null or 0-length.
	 * @param str the string to be examined
	 * @return true if str is null or zero length
	 */
	private static boolean isEmpty(CharSequence str) {
		if (str == null || str.length() == 0)
			return true;
		else
			return false;
	}
	
//	public static boolean checkMacStringColonCount(String macStr){
//		if(macStr.con) {
//			
//		}
//		return false;
//	}
//	
}
